package com.kuangxiaoyang.foodapp;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.google.gson.Gson;

import java.io.IOException;

public class CommentsDetailActivity extends AppCompatActivity {

    private static final String TAG = "CommentDetailActivity";
    private TextView cmdeNameTv;
    private TextView cmdeDesctv;
    private Button backBtn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_comments_detail);
        initView();
        showCommentDetail();
        initEvent();
    }

    private void initView() {
        cmdeNameTv = findViewById(R.id.cm_de_food_name_tv);
        cmdeDesctv = findViewById(R.id.cm_de_food_desc_tv);
        backBtn = findViewById(R.id.back_btn);
    }

    private void initEvent() {
        backBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
    private void showCommentDetail() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {

                    String url = UrlUtil.basePath + "/foodserver/comment/findone/" + UrlUtil.commentId;

                    Gson gson = new Gson();

                    final CommentDetailBean.DataBean data = gson.fromJson(GainDataUtil.GainDataForGet(url), CommentDetailBean.class).getData();

                    CommentsDetailActivity.this.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            cmdeDesctv.setText(data.getComment());
                            cmdeNameTv.setText(UrlUtil.foodName);
                        }
                    });
                    Log.e(TAG, "run: " + data.toString());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}